package com.bigcat.gulimall.demo.java11;

import java.util.List;
import java.util.Map;
import java.util.Set;

/**
 * @author sufer_yuan
 * @since 2023/4/28
 *
 * 集合增强
 * 自 Java 9 开始，Jdk 里面为集合（List/ Set/ Map）都添加了 of 和 copyOf 方法，它们两个都用来创建不可变的集合，来看下它们的使用和区别
 */
public class CollectionUp {

    public static void main(String[] args) {
        List<String> list = List.of("one", "two", "three");
        List<String> copyOfList = List.copyOf(list);
        System.out.println(copyOfList);

        Map<String, String> map = Map.of("Key1", "value1", "key2", "value2");
        Map<String, String> copyOfMap = Map.copyOf(map);
        System.out.println(copyOfMap);

        Set<Integer> set = Set.of(1, 2, 3, 4, 5);
        Set<Integer> copyOfSet = Set.copyOf(set);
        System.out.println(copyOfSet);
    }
}
